import { Button, Space } from 'ant-design-vue'
import { tableColumns, arrivalStatusObj } from './data'

export function useColumns(updateFunction: Function, detailFunction: Function) {
  const getColumns = (column, record) => {
    if (column.dataIndex === 'orderNumber') {
      return <span>P{record.orderNumber}</span>
    } else if (column.dataIndex === 'brandName') {
      return <span>{record.brandName}</span>
    } else if (column.dataIndex === 'warehouseName') {
      return <span>{record.warehouseName}</span>
    } else if (column.dataIndex === 'purchaseTotal') {
      return <span>{record.purchaseTotal}</span>
    } else if (column.dataIndex === 'arrivalStatus') {
      let arrivalStatusStr = ''
      arrivalStatusObj.forEach(model => {
        if (record.arrivalStatus == model.value) {
          arrivalStatusStr = model.label
        }
      })
      return <span>{arrivalStatusStr}</span>
    } else if (column.dataIndex === 'remark') {
      return <span>{record.remark}</span>
    } else if (column.dataIndex === 'createTime') {
      return <span>{record.createTime}</span>
    } else if (column.key === 'action') {
      return (
        <Space>
          <Button
            type='link'
            onClick={() => detailFunction(record.code, record.paymentStatus)}
            v-auth={['base:shop:detail']}
          >
            详情
          </Button>
          <Button
            type='link'
            onClick={() => updateFunction(record.code, record.paymentStatus)}
            v-auth={['base:shop:edit']}
          >
            编辑
          </Button>
        </Space>
      )
    }
  }
  return {
    getColumns,
    tableColumns
  }
}
